package edu.cse484.lab3.task2.getcontacts;

import java.util.Set;

import edu.uw.cs.cse484.lab3.part1.util.Util;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class GetContactsRequest extends Activity {
	private static final String TAG = "GetContactsRequest";
	
    /** Called when the activity is first created. */

	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
		
    	Set<String> emailSet = Util.getContactEmails(this);
        
		Intent result = new Intent();
		
		Log.v(TAG, "Result: " + emailSet.toString());
		// Put resulting emailList in returned intent as a String[]
		String[] resultArray = new String[emailSet.size()];
		emailSet.toArray(resultArray);
		Log.d(TAG, "Setting emailList: " + resultArray.toString() + "(length: " + resultArray.length + ")");
		result.putExtra("Email", resultArray);

		if (getParent() == null) {
			Log.v(TAG, "PARENT NULL");
			setResult(RESULT_OK, result);
		} else {
			Log.i("Parent", "Not NULL");
			getParent().setResult(RESULT_OK, result);
		}
		finish();
	}
}
